Skip to content

fix(graphql-codegen-client-preset): handle Windows-style paths in WASM runtime#595

Merged
kdy1 merged 2 commits into
mainfrom
claude/issue-524-20260321-0029
Mar 21, 2026
Merged

fix(graphql-codegen-client-preset): handle Windows-style paths in WASM runtime#595
kdy1 merged 2 commits into
mainfrom
claude/issue-524-20260321-0029

Conversation

@kdy1
Copy link
Copy Markdown
Member

@kdy1 kdy1 commented Mar 21, 2026

The SWC plugin runs inside a WASM runtime which always uses Unix path semantics, but on Windows the host passes paths with backslashes (e.g. C:\Users\user\project\src\gql). PathBuf in WASM does not treat backslashes as separators, so path computation was silently wrong and produced invalid relative import paths.

Fix by:

  1. Normalizing all input paths (cwd, filename, artifactDirectory) by replacing backslashes with forward slashes before any PathBuf usage.
  2. Replacing the Path::is_absolute() check with an explicit helper that also recognises Windows drive-letter paths (C:/...) as absolute, since Path::is_absolute() returns false for those under WASM/Unix semantics.

Closes #524

Generated with Claude Code

…M runtime

The SWC plugin runs inside a WASM runtime which always uses Unix path
semantics, but on Windows the host passes paths with backslashes
(e.g. C:\Users\user\project\src\gql).  PathBuf in WASM does not treat
backslashes as separators, so path computation was silently wrong and
produced invalid relative import paths.

Fix by:
1. Normalizing all input paths (cwd, filename, artifactDirectory) by
   replacing backslashes with forward slashes before any PathBuf usage.
2. Replacing the Path::is_absolute() check with an explicit helper that
   also recognises Windows drive-letter paths (C:/...) as absolute, since
   Path::is_absolute() returns false for those under WASM/Unix semantics.

Fixes #524

Co-authored-by: Donny/강동윤 <kdy1@users.noreply.github.com>
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Mar 21, 2026

⚠️ No Changeset found

Latest commit: 5afaa5e

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@kdy1 kdy1 enabled auto-merge (squash) March 21, 2026 00:58
@claude
Copy link
Copy Markdown

claude Bot commented Mar 21, 2026

PR Review: fix(graphql-codegen-client-preset): handle Windows-style paths in WASM runtime

The fix is correct and well-reasoned. The root cause (WASM always using Unix path semantics while the host provides Windows paths) is clearly explained, and both normalization steps are necessary.

Positive aspects

  • Removing the unused Path import is clean.
  • Renaming the inner cwd to cwd_path avoids shadowing confusion.
  • The is_absolute_path helper is well-documented and handles the WASM/Unix misclassification issue correctly.
  • Snapshot test confirms the expected relative import path is generated correctly.

Issues

Minor: redundant .to_string() call

In get_relative_import_path:

let resolved_artifact_directory = if is_absolute_path(&artifact_directory) {
    artifact_directory.to_string()  // artifact_directory is already a String

artifact_directory is already a String, so .to_string() is a no-op clone. Either drop it (moving the owned value into the branch) or use artifact_directory.clone() to make the intent explicit. Since the else branch also consumes artifact_directory (via cwd_path.push(&artifact_directory)), you'd need artifact_directory.clone() in the if branch or restructure slightly, e.g.:

let resolved_artifact_directory = if is_absolute_path(&artifact_directory) {
    artifact_directory
} else {
    let mut cwd_path = PathBuf::from(&cwd);
    cwd_path.push(&artifact_directory);
    cwd_path.to_string_lossy().into_owned()
};

Suggestion: add a test for relative Windows paths

The new test covers Windows absolute paths (C:\...), but the backslash normalization also affects relative paths. A test with a relative artifact_directory containing backslashes (e.g. src\\gql) would give fuller coverage of the normalization logic and guard against regression.

Out of scope / known limitation: UNC paths

Windows UNC paths (\\server\share\path) are not handled by is_absolute_path. This is likely acceptable for now, but worth noting in a comment near the helper to avoid future confusion.


Overall this is a solid, focused fix. Addressing the redundant .to_string() and adding a relative-path test would round it out nicely.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6649bbfad2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +81 to +82
let mut file_full_path = PathBuf::from(&cwd);
file_full_path.push(&filename);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Treat absolute Windows filenames before joining with cwd

When filename comes from SWC as an absolute Windows path (for example C:\repo\src\App.tsx), PathBuf::push here still appends it under cwd because the WASM runtime is using Unix path semantics and does not recognize C:/... as absolute. That makes file_s_dirname become something like C:/repo/C:/repo/src, so diff_paths generates imports such as ./../../../../../src/gql/graphql instead of ./gql/graphql. The new test only covers a relative filename, so this case stays broken for hosts that provide absolute filenames.

Useful? React with 👍 / 👎.

@kdy1
Copy link
Copy Markdown
Member Author

kdy1 commented Mar 21, 2026

@claude fix ci

@claude
Copy link
Copy Markdown

claude Bot commented Mar 21, 2026

Claude finished @kdy1's task in 3m 28s —— View job


CI Fixed

  • Check CI status
  • Identify failure: main branch added naming_convention field to GraphQLCodegenOptions; this PR's new get_windows_path_visitor test function didn't include it, causing a compile error in the CI merge commit
  • Add naming_convention: "change-case-all#pascalCase" to get_windows_path_visitor in tests.rs
  • Push fix (commit 5afaa5e)

The CI failure was a merge conflict in test code — main added a naming_convention field to GraphQLCodegenOptions while this PR was open, but the new get_windows_path_visitor function added by this PR didn't include it. Added the missing field to fix compilation.
| Branch

…path test

The naming_convention field was added to GraphQLCodegenOptions in main but
the new get_windows_path_visitor test function introduced by this PR didn't
include it, causing a compile error in the CI merge commit.

Co-authored-by: Donny/강동윤 <kdy1@users.noreply.github.com>
@kdy1 kdy1 merged commit 903317a into main Mar 21, 2026
9 of 11 checks passed
@kdy1 kdy1 deleted the claude/issue-524-20260321-0029 branch March 21, 2026 01:10
kdy1 added a commit that referenced this pull request Mar 21, 2026
## Summary
- Addressed `chatgpt-codex-connector[bot]` review follow-ups across
merged PRs: #585, #591, #592, #593, #594, #595, #597, #598, #599.
- Applied the fixes as 9 separate commits (one commit per original PR)
in a single follow-up branch.

## What Changed
- #585 / #592 (`loadable-components`)
- Fixed source-less default-import matching to honor the configured
local name.
- Updated `ssr: false` detection to respect final object-literal
override order.
  - Added/updated fixtures for both behaviors.
- #591 / #594 (`formatjs`)
- Added JSX member-expression message component support (e.g.
`ReactIntl.FormattedMessage`).
  - Updated #532 regression coverage to validate the `ast: true` path.
- #593 / #595 (`graphql-codegen-client-preset`)
  - Extended `namingConvention` parsing to accept string/object forms.
- Preserved names for `keep`/unknown conventions instead of forcing
PascalCase.
- Fixed Windows absolute `filename` path handling in WASM runtime path
resolution.
  - Added unit coverage for the new config/path behaviors.
- #597 / #599 (`emotion`)
- Ensured tagged-template labels are terminated before sourcemap
comments.
- Added css-prop rewrite support for namespace imports
(`emotionReact.css`).
  - Attached PURE comments to the generated call site span.
  - Updated emotion fixtures accordingly.
- #598 (docs)
- Corrected capability descriptions in `packages/jest/README.tmpl.md`
and `packages/swc-sdk/README.tmpl.md`.

## Validation
- `cargo test -p swc_plugin_loadable_components --test fixture --
--ignored`
- `cargo test -p swc_plugin_graphql_codegen_client_preset`
- `cargo test -p swc_emotion --test fixture -- --ignored`
- `pnpm -C /Users/kdy1/.codex/worktrees/17e6/plugins/packages/formatjs
test`

All passed (formatjs has an existing non-blocking Vitest warning about
an un-awaited rejects assertion).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

graphql-codegen-client-preset doesn't work with absolute path aliases in Vite on Windows

2 participants